package com.bt.lms.dao.servise.impl;

import com.bt.lms.entity.User;
import com.bt.lms.dao.servise.LoginDao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author 徐大永
 */
public class LoginDaoImpl implements LoginDao {

    @Override
    public boolean select(String sql, User user) {

        //需要用到的属性
        String accountNumber = user.getAccountNumber();
        String password = user.getPassword();

        try {
            //连接
            Connection connection = UserDaoImpl.pond();
            //预编译
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1,accountNumber);
            //执行
            ResultSet resultSet = preparedStatement.executeQuery();
            resultSet.next();
            String pwd = resultSet.getString(1);
            //关闭资源
            preparedStatement.close();
            connection.close();

            return password.equals(pwd);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

    }
}
